package com.supreme.proxyserver.controller;

import com.supreme.commonboot.utils.AjaxResp;
import com.supreme.proxyserver.bean.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "bean")
public class BeanController {

    private final HelloBean helloBean;
    private final SupremeBean supremeBean;

//    @Resource(name = "redisStringTemplate3")
//    private StringRedisTemplate redisStringTemplate3;

//    @Resource(name = "redisStringTemplate4")
//    private StringRedisTemplate redisStringTemplate4;

//    @Resource(name = "redisTemplate3")
//    private RedisTemplate<String, Serializable> redisTemplate3;

//    @Resource(name = "redisTemplate4")
//    private RedisTemplate<String, Serializable> redisTemplate4;

    @Autowired
    public BeanController(HelloBean helloBean, SupremeBean supremeBean) {
        this.helloBean = helloBean;
        this.supremeBean = supremeBean;
    }

    @GetMapping(value = "beanMapper")
    public AjaxResp beanMapper() {
        Car car = new Car( "Morris", 5, 88);
        CarDto carDto = CarMapper.INSTANCE.carToCarDto(car);
        return new AjaxResp(carDto);
    }

    @GetMapping(value = "hello")
    public AjaxResp getHelloBean() {
        String helloBeanName = this.helloBean.getName(" what fuck man");
        this.supremeBean.setSupremeValue("supreme server is great");
        String supremeValue = this.supremeBean.getSupremeValue();
        return new AjaxResp()
                .append("supreme", supremeValue)
                .append("hello", helloBeanName);
    }

    /*@PostMapping(value = "setRedis3")
    public AjaxResp setRedis3(@RequestBody JSONObject jsonObject) {
        final String key = jsonObject.getString("key");
        final String val = jsonObject.getString("val");
        this.redisStringTemplate3.opsForValue().set(key, val);
        return new AjaxResp();
    }*/

    /*@GetMapping(value = "getRedis3/{key}")
    public AjaxResp getRedis3(@PathVariable(value = "key") String key) {
        final ValueOperations<String, String> operations = this.redisStringTemplate3.opsForValue();
        final String result = operations.get(key);
        return new AjaxResp(result);
    }*/

    /*@PostMapping(value = "setRedis4")
    public AjaxResp setRedis4(@RequestBody JSONObject jsonObject) {
        final String key = jsonObject.getString("key");
        final String val = jsonObject.getString("val");
        this.redisStringTemplate4.opsForValue().set(key, val);
        return new AjaxResp();
    }*/
}
